﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GeoSketch2.Archaeo
{
    /// <summary>
    /// The form to display or modify information about the current area
    /// </summary>
    public partial class ExcavationAreaInfoForm : Form
    {
        #region Fields
        Viewport Viewport;

        ExcavationArea CurrentArea; 
        #endregion

        #region Constructor
        /// <summary>
        /// The form to display or modify information about the current area
        /// </summary>
        public ExcavationAreaInfoForm(Viewport Viewport)
        {
            InitializeComponent();

            this.Viewport = Viewport;
            this.CurrentArea = Viewport.CurrentExcavationArea;

            TextBox_AreaName.Text = CurrentArea.Name;
            LoadArcheologistsList();
            DateTimePicker_CreationTime.Value = CurrentArea.CreationTime;
        } 
        #endregion

        #region Events
        private void Button_OK_Click(object sender, EventArgs e)
        {
            SaveChanges();
            ((DrawingForm)Viewport.DisplayControl.Parent).LoadSiteHierarchy();
            ((DrawingForm)Viewport.DisplayControl.Parent).SetFormTitle();
            this.Close();
        }

        private void Button_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        } 
        #endregion

        #region Methods
        void LoadArcheologistsList()
        {
            foreach (string s in Viewport.Project.ArchaeologistsList)
            {
                ComboBox_Archaeologist.Items.Add(s);
            }
            ComboBox_Archaeologist.Text = CurrentArea.ArchaeologistName;
        }

        void SaveChanges()
        {
            CurrentArea.Name = TextBox_AreaName.Text;
            CurrentArea.ArchaeologistName = ComboBox_Archaeologist.Text;
            CurrentArea.CreationTime = DateTimePicker_CreationTime.Value;

            Viewport.Project.ArchaeologistsList.Clear();
            Viewport.Project.ArchaeologistsList.Add(ComboBox_Archaeologist.Text);
            foreach (string s in ComboBox_Archaeologist.Items)
            {
                if (!Viewport.Project.ArchaeologistsList.Contains(s))
                {
                    Viewport.Project.ArchaeologistsList.Add(s);
                }
            }
        } 
        #endregion
    }
}
